<%@page import="com.google.appengine.api.blobstore.BlobKey"%>
<%@page import="com.google.appengine.api.images.ImagesServiceFactory"%>
<%@page import="com.google.appengine.api.images.ImagesService"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.TreeMap"%>
<%@page import="entities.User"%>
<%
User user = (User) request.getAttribute("user");
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
String appId = (String) request.getAttribute("appId");
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
ImagesService imagesService = ImagesServiceFactory.getImagesService();
%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/user/layouts/header.jsp" />
<script type="text/javascript">
jQuery(document).ready(function () {
	jQuery("#profileTab li:eq(1)").addClass("active");
});
</script>
                    <!-- change profile
					================================================== -->
                    <div class="tab-pane active" id="profile">
                    	<% if (success != null) { %>
			            <div class="alert alert-success"><%=success %></div>
			            <% } %>
                    
                        <form method="post" class="form-horizontal" action="<%= blobstoreService.createUploadUrl("/profile/change-avatar") %>" enctype="multipart/form-data">                 	
                            <div class="row-fluid">
                            	<div class="span3">
                                	<% 
										if (user.getAvatar() != null && !user.getAvatar().isEmpty())  {
											 BlobKey blobKey = new BlobKey(user.getAvatar());
									%>
									<img alt="" src="<%=imagesService.getServingUrl(blobKey) %>=s120-c"><br />
									<% } else { %>							
									<img class="img-full-width" src="/user/images/icon-author.jpg" />
									<% } %>
                                </div>
                                <div class="span9">
                                	<div class="control-group">
                                		<input type="file" id="avatar_file" name="avatar" value="Upload" />
                                    </div>
                                	<button class="btn btn-primary" type="submit">Change my avatar</button>
                                	<input type="hidden" name="userid" value="<%=user.getId()%>">
                                	<input type="hidden" name="appId" value="<%=appId%>">
                                </div>
                            </div>
                        </form>
                    </div>
                    
                    
<jsp:include page="/user/layouts/footer.jsp" />